package test0102;

public class Platform {
    String name;
    Order[] arr = new Order[3];
    int i = 0;

    public Platform() {
    }

    public Platform(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Platform{" +
                "name='" + name + '\'' +
                '}';
    }
    public void add(Order order) {
        arr[i] = order;
        i++;

    }

    public void printAll() {
        for (Order order : arr) {
            System.out.println(order);
        }
    }


    public Order findMaxOrder() {
        Order a = arr[0];
        for (Order order : arr) {
            if (order.getMoney() > a.getMoney()) {
                a = order;
            }
        }
        return a;
    }

    public Order findMinOrder() {
        Order a = arr[0];
        for (Order order : arr) {
            if (order.getMoney() < a.getMoney()) {
                a = order;
            }
        }
        return a;
    }

    public Order findOrderByName(String name) {
        Order a = null;
        for (Order order : arr) {
            if (order.getName() == name){
                a = order;
            }
        }
        return a;
    }

    public double calculateAverage() {
        double sum = 0;
        for (Order order : arr) {
            sum += order.getMoney();
        }
        return sum / arr.length;
    }
}
